#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

// this header is basically self-documenting

#define MOV_LEN 40


struct game_info {
	int loadtime;
	int turntime;
	int rows;
	int cols;
	int turns;
    int current_turn;
	int viewradius_sq;
	int attackradius_sq;
	int spawnradius_sq;
    int seed;
	char *map;
};

struct basic_ant {
    int row;
    int col;
    char player;
};

struct my_ant {
    int id;
    int row;
    int col;
    char movement[MOV_LEN];
    char last_move;
    char order;
    char d2t; //direction to target
    int group;
    int t_row; // target row
    int t_col; // target col
};

struct food {
    int row;
    int col;
    int a_i; // ant index, kazde kolo se musi nastavit
};

struct hill {
    int row;
    int col;
    char player;
};

struct game_state {
    struct my_ant *my_ants;
    struct basic_ant *enemy_ants;
    struct food *food;
    struct basic_ant *dead_ants;
    struct hill *hill;
    
    int my_count;
    int enemy_count;
    int food_count;
    int dead_count;
    int hill_count;
    int enemy_hill_count;

    int my_ant_index;
};

struct xmove{
    struct xmove *next; // next in list
    struct xmove *gnext; // next in gen
    struct xmove *prev; // prev in expand
    int row;
    int col;
    int dir;
    int step;
    int dist;
};

// functions ......................................

// initAnts.c
void _init_ants(char *data, struct game_info *game_info);
void _init_game(struct game_info *game_info, struct game_state *game_state);
void _init_map(char *data, struct game_info *game_info);

// mAnts.c
int abs(int x);
int sgn(int x);
int row_distance(int row1, int row2, struct game_info *Info);
int col_distance(int col1, int col2, struct game_info *Info);
int distance(int row1, int col1, int row2, int col2, struct game_info *Info);
int steps_distance(int row1, int col1, int row2, int col2, struct game_info *Info);
char can_ant_move(int ant_row, int ant_col, char plan_char_move, struct game_info *Info);
void move(int index, char dir, struct game_state* Game, struct game_info* Info);
char opposite_direction(char direction);
int get_d2t(int start_row, int start_col, int target_row, int target_col, struct game_info *Info);
void deinit_xmove(struct xmove *Xmove);
int is_xmove_pointer_in_list(struct xmove *newXmove, struct xmove *listXmove);
int is_xmove_in_list(int row, int col, struct xmove *listXmove);
struct xmove * insert_xmove(struct xmove *newXmove, struct xmove *listXmove);
int depth_xmove_prev(struct xmove *Xmove);
//void debug_print_xmove_list(struct xmove *listXmove);
char* plan_movement_aStar(int start_row, int start_col, int target_row, int target_col, struct game_info *Info);
char *get_line(char *text);
int main(int argc, char *argv[]);
void debug_log (char * text);

// mCode.c
char easy_plan_dir(int start_row, int start_col, int target_row, int target_col, struct game_info *Info);
char plan_move(struct my_ant *ant, struct food *target_food, struct game_info *Info);
char right_sidewalk(char direction);
void plan_movement();
void plan_ant_order(int m_i, struct game_state *Game, struct game_info *Info);
void do_turn(struct game_state *Game, struct game_info *Info);

